<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css" />
<jsp:include page="../inc.jsp"></jsp:include>
	<jsp:include page="../head.jsp"/>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>报表中心-业务报表</title>
<style>
		input{
			width:120px;
			height:18px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		select{
			height:20px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		.searchBox{
			width:100%; 
			height:80px;
		}
		.searchBox li{
			float:left;
			margin-top:5px;
			margin-left:5px;
			margin-right:5px;
		}
		.tableOntab td{
			height:37px;
			border-right:none;
		}
		.tableOntab .borderNone{
			border-bottom:none;
		}
		.query{
			margin-left:5px;
		}
		/*使按钮居中*/
		.autoBoxTwo{
			width:180px;
			height:26px;
			margin:15px auto; 
		}
		input::-ms-clear{display:none;}
</style>

<script type="text/javascript">
	$(function(){
		//加载表格信息
		dataGrid = $('#orderTable').datagrid({
			url:'${ctx}/search/contractDetailForPlatform?temp='+Math.random(),
			//  url:'${ctx}/json/data_pay.json',
			width:1600,
			striped : true,
			singleSelect : true,
			idField : 'flightIdList',
			pageSize : 10,
			pageList : [10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
			//sortName : 'id',
			//sortOrder : 'asc',
			method : 'get',
			toolbar:'#toolbar',
			pagination:true,
			
			columns:[[
			          {
							width : '80',
							title : 'id',
							field : 'id',
							hidden : true,
							sortable : true
						},{
				width : '80',
				title : '航班号',
				align : 'center',
				field : 'airlineId',
				formatter : function(value,row){
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:70px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].airlineNumber+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].airlineNumber+'</span>'
						}
						
					}
					return str;
				}
			},{
				width : '135',
				title : '出发',
				align : 'center',
				field : 'charterTypeStr',
				formatter : function(value,row){
					//var table='<table class="tableOntab" style="width:100px;"><tr><td>'+row.toStartAirportName+'('+row.toStartAirportCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.backStartAirportName+'('+row.backStartAirportCode+')'+'</td></tr></table>';
					//return table;
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].deptCity+'('+row.list[0].deptCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].deptCity+'('+row.list[1].deptCode+')'+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].deptCity+'('+row.list[0].deptCode+')'+'</span>'
						}
						
					}
					return str;
				}
			},{
				width : '140',
				title : '到达',
				align : 'center',
				field : 'scheduleId',
				formatter : function(value,row){
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].arrCity+'('+row.list[0].arrCode+')'+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].arrCity+'('+row.list[1].arrCode+')'+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].arrCity+'('+row.list[0].arrCode+')'+'</span>'
						}
						
					}
					return str;
				}
			},{
				width : '80',
				title : '出发日期',
				align : 'center',
				field : 'scheduleIdStr',
				formatter : function(value,row){
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].deptDate+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].deptDate+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].deptDate+'</span>'
						}
						
					}
					return str;
				}
			},{
				width : '55',
				title : '出发时刻',
				align:'center',
				field : 'journeyType',
				formatter : function(value,row){
					var toIntervalDay=row.intervalDay;
					var _toIntervalDay="";
					if (toIntervalDay >= 1){
						_toIntervalDay="+"+toIntervalDay;
					}; 
					
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:50px;"><tr><td>'+row.list[0].deptTime+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].deptTime+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].deptTime+'</span>'
						}
						
					}
					return str;
					
				}
			},{
				width : '55',
				title : '到达时刻',
				align:'center',
				field : 'toDate',
				formatter : function(value,row){
					var toIntervalDay=row.intervalDay;
					var _toIntervalDay="";
					if (toIntervalDay >= 1){
						_toIntervalDay="+"+toIntervalDay;
					}; 
					
					var str="";
					if(row.list!=null){
						if(row.list.length==2){
							str='<table class="tableOntab" style="width:50px;"><tr><td>'+row.list[0].arrTime+'</td>'+'</tr><tr>'+'<td class="borderNone">'+row.list[1].arrTime+'</td></tr></table>';
						}else if(row.list.length==1){
							//str='<table class="tableOntab" style="width:60px;"><tr><td>'+row.list[0].airlineNumber+'</td>'+'</tr></table>';
							str='<span>'+row.list[0].arrTime+'</span>'
						}
						
					}
					return str;
				}
			},{
				width : '160',
				title : '平台订单号',
				align:'center',
				field : 'orderNumber'
			},{
				width : '160',
				title : '供应商订单号',
				align:'center',
				field : 'pssOrderNumber'
			},{
				width : '60',
				title : '业务状态',
				align:'center',
				field : 'order',
				formatter:function(value,row){
					return CommonConverter.toOrderBizStatusStr(row.orderStatus);
				}
			},{
				width : '65',
				title : '财务状态',
				align:'center',
				field : 'fiance',
				formatter:function(value,row){
					return CommonConverter.toOrderPayStatusStr(row.financeStatus);
				}
			},{
				width : '100',
				title : '供应商',
				align:'center',
				field : 'sellerName',
			},{
				width : '100',
				title : '采购商',
				align:'center',
				field : 'backDate',
				formatter : function(value,row){
					var value='<p>买：'+row.buyerName+'</p>'+
							  '<p>真实姓名：'+CommonConverter.toEmptyString(row.createuserName)+'</p>'+'<p>联系电话：'+CommonConverter.toEmptyString(row.mobile)+'</p>';
					return value;
				}
			},{
				width : '50',
				title : '数量',
				align:'center',
				field : 'purchQuantity'
			},{
				width : '60',
				title : '实际出票',
				align:'center',
				field : 'actualTicketedCount',
				formatter:function(value,row){
					if(row.orderStatus!=5&&row.orderStatus!=0){
						return CommonConverter.toEmptyString(row.actualTicketedCount);
					}else{
						return 0;
					}
					
				}
			},{
				width : '50',
				title : '单价',
				align:'center',
				field : 'sellingPrice'
			},{
				width : '70',
				title : '应收金额',
				align:'center',
				field : 'se',
				formatter:function(value,row){
					if(row.orderStatus!=5){
						return "￥"+(row.purchQuantity)*(row.sellingPrice);
					}else{
						return 0;
					}
				}
			},{
				width : '70',
				title : '实收金额',
				align:'center',
				field : 'sm',
				formatter:function(value,row){
					var total=row.sum;
					if(row.orderStatus>=2&&row.orderStatus!=5){
						return "￥"+total;
					}else{
						total=0;
						return total;
					}
				}
				
			},{
				width : '70',
				title : '佣金',
				align:'center',
				field : 'charges'
				
			},{
				width : '70',
				title : '应付金额',
				align:'center',
				field : 'ak',
				formatter:function(value,row){
					if(row.orderStatus!=5&&row.sum!=null&&row.sum!=undefined){
						var paymoney=parseFloat(row.sum)-parseFloat(row.charges);
						return "￥"+paymoney;
					}else{
						return 0;
					}
				}
			},{
				width : '70',
				title : '实付金额',
				align:'center',
				field : 'ck',
				formatter:function(value,row){
					var paymoney=parseFloat(row.sum)-parseFloat(row.charges);
					if(row.orderStatus==4){
						return "￥"+paymoney;
					}else{
						paymoney=0;
						return paymoney;
					}
					
				}
			}
			] ]
		});
		//点击查询 重新加载列表
		$("#query").click(function(){
			//获取参数
			var orderStatus=$("#orderStatus").val(); //订单状态
			var toStartAirportCode=$("#_startCity").val();//出发城市
			var toEndAirportCode=$("#_endCity").val(); //到达城市
			var toStartDate=$("#_startTime").datebox('getValue');//开始日期
			var toEndDate=$("#_endTime").datebox('getValue');//结束日期
			var buyerName=$("#buyerName").val();//采购商
			var sellerName=$("#sellerName").val();//供应商
			var financeStatus=$("#financeStatus").val(); //财务状态
			if(typeof(toStartAirportCode) == 'undefined'){
				toStartAirportCode = "";
			}
			if(typeof(toEndAirportCode) == 'undefined'){
				toEndAirportCode = "";
			}
			$('#orderTable').datagrid('load',{"orderStatus":orderStatus,"toStartAirportCode":toStartAirportCode,"toEndAirportCode":toEndAirportCode,"toStartDate":toStartDate,"toEndDate":toEndDate,"buyerName":buyerName,"sellerName":sellerName,"financeStatus":financeStatus,"temp":Math.random()});
			//$('#orderTable').datagrid('load',queryVo);
		});
		
	});
	//导出表格
	function exportExcel(){
		var orderStatus=$("#orderStatus").val(); //订单状态
		var toStartAirportCode=$("#_startCity").val();//出发城市
		var toEndAirportCode=$("#_endCity").val(); //到达城市
		var toStartDate=$("#_startTime").datebox('getValue');//开始日期
		var toEndDate=$("#_endTime").datebox('getValue');//结束日期
		var buyerName=$("#buyerName").val();//采购商
		var sellerName=$("#sellerName").val();//供应商
		var financeStatus=$("#financeStatus").val(); //财务状态
		if(typeof(toStartAirportCode) == 'undefined'){
			toStartAirportCode = "";
		}
		if(typeof(toEndAirportCode) == 'undefined'){
			toEndAirportCode = "";
		}
		var url = "${ctx}/excel/exportSheets3?orderStatus="+orderStatus
		+"&toStartAirportCode="+toStartAirportCode
		+"&toEndAirportCode="+toEndAirportCode
		+"&toStartDate="+toStartDate
		+"&toEndDate="+toEndDate
		+"&buyerName="+buyerName
		+"&sellerName="+sellerName
		+"&financeStatus="+financeStatus
		+"&temp="+Math.random();
		window.location.href = url;
	};
</script>
</head>
<body>
	<div>
		 <div >
			<ul class="searchBox">
					<div style='overflow:hidden;'>
					<li>
					          统计日期 ：<input class="easyui-datebox" id="_startTime" style="width: 120px" />
						至<input class="easyui-datebox" id="_endTime" style="width: 120px" />
					</li>
					<li>采购商：<input  id="buyerName" name="charterType" class="easyui-textbox" style="width: 120px"/></li>
					<li>供应商：<input  id="sellerName" name="charterType" class="easyui-textbox" style="width: 120px"/></li>
					<li>
						业务状态：
						<select id="orderStatus" style="width: 100px;">
							<option value="-1">所有订单</option>
							<option value="0">待支付</option>
							<option value="2">待出票</option>
							<option value="4">出票完成</option>
							<option value="5">已取消</option>
						</select>
					</li>
					<li>
						财务状态：
						<select id="financeStatus" style="width: 100px;">
							<option value="-1">全部</option>
							<option value="1">收款待审核</option>
							<option value="2">已收款</option>
							<option value="3">待提现</option>
							<option value="4">提现待审核</option>
							<option value="5">提现待支付</option>
							<option value="6">已付款</option>
						</select>
						</div>
					</li>
					<li>出发城市：
					<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
					<input id="_startCity" name="_startCity" type="hidden" value="" />
					</li>
					<li>到达城市：
					<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
					<input id="_endCity" name="_endCity" type="hidden" value="" />
					</li>
					<li><button class='query' id="query">查询</button></li>
					<li><button class='query' onclick="exportExcel()" >导出</button></li>
				</ul>
			</div>
			 <div>
				<table id="orderTable" class="easyui-datagrid"></table>
			</div>
		</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"/>
</body>
</html>